//@author A0096440E
#include "stdafx.h"
#include "CppUnitTest.h"

using namespace Microsoft::VisualStudio::CppUnitTestFramework;

namespace TaskItUnitTest {
	TEST_CLASS(TaskItSchedulerTest) {
public:

	//@author A0099983B
	TEST_METHOD(MarkFunctionInvalidTaskNumber) {
		TaskItScheduler myScheduler;
		string correctString = INVALID_MARK + NEW_LINE;

		myScheduler.addTask("Dance", "Studio", "0900", "1000", "Recreation", "140314");
		myScheduler.addTask("Dances", "Studio", "1000", "1100", "Recreation", "140314");
		myScheduler.addTask("Danced", "Studio", "1100", "1200", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.markTask("4"));
	}
	
	TEST_METHOD(MarkFunctionValidTaskNumber) {
		TaskItScheduler myScheduler;
		string correctString = MESSAGE_MARKED + "\r\n\r\n     Activity: Dances\r\n      Venue: Studio\r\nTime Start: 10:00\r\n Time End: 11:00\r\n  Category: Recreation\r\n        Date: 140314\r\n      Status: Done\r\n";

		myScheduler.addTask("Dance", "Studio", "0900", "1000", "Recreation", "140314");
		myScheduler.addTask("Dances", "Studio", "1000", "1100", "Recreation", "140314");
		myScheduler.addTask("Danced", "Studio", "1100", "1200", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.markTask("2"));
	}

	//@author A0096440E
	TEST_METHOD(AddFunctionTaskInvalidDateWithCharacters) {
		TaskItScheduler myScheduler;
	
		string correctString = INVALID_DATE + NEW_LINE;

		Assert::AreEqual(correctString, myScheduler.addTask("Dance", "Studio", "0900", "1000", "Recreation", "AAAAAA"));
	}
	
	TEST_METHOD(AddFunctionTaskInvalidDateWithTooFewNumbersInserted) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_DATE + NEW_LINE;

		Assert::AreEqual(correctString, myScheduler.addTask("Dance", "Studio", "0900", "1000", "Recreation", "14031"));
	}

	TEST_METHOD(AddFunctionTaskInvalidDateWithWrongMonth) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_DATE + NEW_LINE;

		Assert::AreEqual(correctString, myScheduler.addTask("Dance", "Studio", "0900", "1000", "Recreation", "141314"));
	}
	
	TEST_METHOD(AddFunctionTaskInvalidDateWithWrongDay) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_DATE + NEW_LINE;

		Assert::AreEqual(correctString, myScheduler.addTask("Dance", "Studio", "0900", "1000", "Recreation", "330314"));
	}
	
	TEST_METHOD(AddFunctionTaskInvalidStartTimeWithTooFewNumbersInserted) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME + NEW_LINE;

		Assert::AreEqual(correctString, myScheduler.addTask("Dance", "Studio", "090", "1000", "Recreation", "14031"));
	}
	
	TEST_METHOD(AddFunctionTaskInvalidStartTimeWithCharacters) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME + NEW_LINE;

		Assert::AreEqual(correctString, myScheduler.addTask("Dance", "Studio", "AAAA", "1000", "Recreation", "140314"));
	}

	TEST_METHOD(AddFunctionTaskInvalidStartTimeWithWrongHour) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME + NEW_LINE;

		Assert::AreEqual(correctString, myScheduler.addTask("Dance", "Studio", "2539", "1000", "Recreation", "140314"));
	}

	TEST_METHOD(AddFunctionTaskInvalidStartTimeWithWrongMin) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME + NEW_LINE;

		Assert::AreEqual(correctString, myScheduler.addTask("Dance", "Studio", "0999", "1000", "Recreation", "140314"));
	}

	TEST_METHOD(AddFunctionTaskInvalidEndTimeWithCharacters) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME + NEW_LINE;

		Assert::AreEqual(correctString, myScheduler.addTask("Dance", "Studio", "0900", "AAAA", "Recreation", "140314"));
	}

	TEST_METHOD(AddFunctionTaskInvalidEndTimeWithTooFewNumbersInserted) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME + NEW_LINE;

		Assert::AreEqual(correctString, myScheduler.addTask("Dance", "Studio", "0900", "100", "Recreation", "140314"));
	}
	
	TEST_METHOD(AddFunctionTaskInvalidEndTimeWithWrongHour) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME + NEW_LINE;

		Assert::AreEqual(correctString, myScheduler.addTask("Dance", "Studio", "0900", "2549", "Recreation", "140314"));
	}

	TEST_METHOD(AddFunctionTaskInvalidEndTimeWithWrongMin) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME + NEW_LINE;

		Assert::AreEqual(correctString, myScheduler.addTask("Dance", "Studio", "0900", "1099", "Recreation", "140314"));
	}

	TEST_METHOD(AddFunctionTaskInvalidTimeWithStartTimeLaterThanEndTime) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME_COMBINATION + NEW_LINE;

		Assert::AreEqual(correctString, myScheduler.addTask("Dance", "Studio", "1300", "1200", "Recreation", "140314"));
	}

	TEST_METHOD(AddFunctionTaskInvalidActivity) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_ADD + NEW_LINE;

		Assert::AreEqual(correctString, myScheduler.addTask("-", "Studio", "0900", "1000", "Recreation", "140314"));
	}

	TEST_METHOD(AddFunctionTaskInvalidTimeWithoutDate) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_DATE_TIME + NEW_LINE;

		Assert::AreEqual(correctString, myScheduler.addTask("Dance", "Studio", "0900", "1000", "Recreation", "-"));
	}

	TEST_METHOD(AddFunctionTaskWithClashFoundWithSameStartTimeAndSameEndTime) {
		TaskItScheduler myScheduler;

		string correctString = CLASH_FOUND + "\r\n\r\n     Activity: Dance\r\n      Venue: Studio\r\nTime Start: 09:00\r\n Time End: 10:00\r\n  Category: Recreation\r\n        Date: 140314\r\n      Status: Not Done\r\n";
		myScheduler.addTask("Dance", "Studio", "0900", "1000", "Recreation", "140314");

		Assert::AreEqual(correctString, myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314"));
	}

	TEST_METHOD(AddFunctionTaskWithClashFoundWithStartTimeEarlierThanEndTimeClash) {
		TaskItScheduler myScheduler;

		string correctString = CLASH_FOUND + "\r\n\r\n     Activity: Dance\r\n      Venue: Studio\r\nTime Start: 09:00\r\n Time End: 10:00\r\n  Category: Recreation\r\n        Date: 140314\r\n      Status: Not Done\r\n";
		myScheduler.addTask("Dance", "Studio", "0900", "1000", "Recreation", "140314");

		Assert::AreEqual(correctString, myScheduler.addTask("Dances", "Studio", "0930", "1030", "Recreation", "140314"));
	}

	TEST_METHOD(AddFunctionTaskWithClashFoundWithEndTimeLaterThanStartTimeClash) {
		TaskItScheduler myScheduler;

		string correctString = CLASH_FOUND + "\r\n\r\n     Activity: Dance\r\n      Venue: Studio\r\nTime Start: 09:00\r\n Time End: 10:00\r\n  Category: Recreation\r\n        Date: 140314\r\n      Status: Not Done\r\n";
		myScheduler.addTask("Dance", "Studio", "0900", "1000", "Recreation", "140314");

		Assert::AreEqual(correctString, myScheduler.addTask("Dances", "Studio", "0830", "0930", "Recreation", "140314"));
	}

	TEST_METHOD(AddFunctionTaskWithCorrectParameters) {
		TaskItScheduler myScheduler;

		string correctString = MESSAGE_ADDED + "\r\n\r\n     Activity: Dances\r\n      Venue: Studio\r\nTime Start: 09:00\r\n Time End: 10:00\r\n  Category: Recreation\r\n        Date: 140314\r\n      Status: Not Done\r\n\r\nNote: Date specified has already passed.";

		Assert::AreEqual(correctString, myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314"));
	}
	
	TEST_METHOD(EditFunctionTaskInvalidDateWithCharacters) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_DATE + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dance", "Studio", "0900", "1000", "Recreation", "AAAAAA"));
	}

	TEST_METHOD(EditFunctionTaskInvalidDateWithTooFewNumbersInserted) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_DATE + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dance", "Studio", "0900", "1000", "Recreation", "14031"));
	}

	TEST_METHOD(EditFunctionTaskInvalidDateWithWrongMonth) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_DATE + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dance", "Studio", "0900", "1000", "Recreation", "141314"));
	}

	TEST_METHOD(EditFunctionTaskInvalidDateWithWrongDay) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_DATE + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dance", "Studio", "0900", "1000", "Recreation", "330314"));
	}

	TEST_METHOD(EditFunctionTaskInvalidStartTimeWithTooFewNumbersInserted) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dance", "Studio", "090", "1000", "Recreation", "14031"));
	}

	TEST_METHOD(EditFunctionTaskInvalidStartTimeWithCharacters) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dance", "Studio", "AAAA", "1000", "Recreation", "140314"));
	}

	TEST_METHOD(EditFunctionTaskInvalidStartTimeWithWrongHour) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dance", "Studio", "2539", "1000", "Recreation", "140314"));
	}

	TEST_METHOD(EditFunctionTaskInvalidStartTimeWithWrongMin) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dance", "Studio", "0999", "1000", "Recreation", "140314"));
	}

	TEST_METHOD(EditFunctionTaskInvalidEndTimeWithCharacters) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dance", "Studio", "0900", "AAAA", "Recreation", "140314"));
	}

	TEST_METHOD(EditFunctionTaskInvalidEndTimeWithTooFewNumbersInserted) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dance", "Studio", "0900", "100", "Recreation", "140314"));
	}

	TEST_METHOD(EditFunctionTaskInvalidEndTimeWithWrongHour) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dance", "Studio", "0900", "2549", "Recreation", "140314"));
	}
	
	TEST_METHOD(EditFunctionTaskInvalidEndTimeWithWrongMin) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dance", "Studio", "0900", "1099", "Recreation", "140314"));
	}

	TEST_METHOD(EditFunctionTaskInvalidTimeWithStartTimeLaterThanEndTime) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_TIME_COMBINATION + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dance", "Studio", "1300", "1200", "Recreation", "140314"));
	}

	TEST_METHOD(EditFunctionTaskInvalidActivity) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_ADD + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "-", "Studio", "0900", "1000", "Recreation", "140314"));
	}

	TEST_METHOD(EditFunctionTaskInvalidTimeWithoutDate) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_DATE_TIME + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dance", "Studio", "0900", "1000", "Recreation", "-"));
	}

	TEST_METHOD(EditFunctionInvalidTaskNumber) {
		TaskItScheduler myScheduler;

		string correctString = INVALID_EDIT + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("2", "Dance", "Studio", "0900", "1000", "Recreation", "140314"));
	}

	TEST_METHOD(EditFunctionTaskWithClashFoundWithSameStartTimeAndSameEndTime) {
		TaskItScheduler myScheduler;

		string correctString = CLASH_FOUND_EDITED + "\r\n\r\n     Activity: Dances\r\n      Venue: Studio\r\nTime Start: 11:00\r\n Time End: 12:00\r\n  Category: Recreation\r\n        Date: 140314\r\n      Status: Not Done\r\n\r\n" + CLASH_FOUND_UNDO;
		myScheduler.addTask("Dance", "Studio", "0900", "1000", "Recreation", "140314");
		myScheduler.addTask("Dancing", "Studio", "1100", "1200", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dances", "Studio", "1100", "1200", "Recreation", "140314"));
	}

	TEST_METHOD(EditFunctionTaskWithClashFoundWithStartTimeEarlierThanEndTimeClash) {
		TaskItScheduler myScheduler;

		string correctString = CLASH_FOUND_EDITED + "\r\n\r\n     Activity: Dances\r\n      Venue: Studio\r\nTime Start: 11:30\r\n Time End: 12:30\r\n  Category: Recreation\r\n        Date: 140314\r\n      Status: Not Done\r\n\r\n" + CLASH_FOUND_UNDO;
		myScheduler.addTask("Dance", "Studio", "0900", "1000", "Recreation", "140314");
		myScheduler.addTask("Dancing", "Studio", "1100", "1200", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dances", "Studio", "1130", "1230", "Recreation", "140314"));
	}

	TEST_METHOD(EditFunctionTaskWithClashFoundWithEndTimeLaterThanStartTimeClash) {
		TaskItScheduler myScheduler;

		string correctString = CLASH_FOUND_EDITED + "\r\n\r\n     Activity: Dances\r\n      Venue: Studio\r\nTime Start: 10:30\r\n Time End: 11:30\r\n  Category: Recreation\r\n        Date: 140314\r\n      Status: Not Done\r\n\r\n" + CLASH_FOUND_UNDO;
		myScheduler.addTask("Dance", "Studio", "0900", "1000", "Recreation", "140314");
		myScheduler.addTask("Dancing", "Studio", "1100", "1200", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dances", "Studio", "1030", "1130", "Recreation", "140314"));
	}

	TEST_METHOD(EditFunctionTaskWithCorrectParameters) {
		TaskItScheduler myScheduler;

		string correctString = MESSAGE_EDITED + "\r\n\r\n     Activity: Dance\r\n      Venue: Studio\r\nTime Start: 09:00\r\n Time End: 10:00\r\n  Category: Recreation\r\n        Date: 140314\r\n      Status: Not Done\r\nto\r\n\r\n     Activity: Dances\r\n      Venue: Studio\r\nTime Start: 09:00\r\n Time End: 10:00\r\n  Category: Recreation\r\n        Date: 140314\r\n      Status: Not Done\r\n";
		myScheduler.addTask("Dance", "Studio", "0900", "1000", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.editTask("1", "Dances", "Studio", "0900", "1000", "Recreation", "140314"));
	}

	//@author A0099983B
	TEST_METHOD(DeleteFunctionInvalidTaskNumber) {
		TaskItScheduler myScheduler;
		string correctString = INVALID_DELETE + NEW_LINE;

		myScheduler.addTask("Dance", "Studio", "0900", "1000", "Recreation", "140314");
		myScheduler.addTask("Dances", "Studio", "1000", "1100", "Recreation", "140314");
		myScheduler.addTask("Danced", "Studio", "1100", "1200", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.deleteTask("4"));
	}

	TEST_METHOD(DeleteFunctionValidTaskNumber) {
		TaskItScheduler myScheduler;
		string correctString = MESSAGE_DELETED + "\r\n\r\n     Activity: Dance\r\n      Venue: Studio\r\nTime Start: 09:00\r\n Time End: 10:00\r\n  Category: Recreation\r\n        Date: 140314\r\n      Status: Not Done\r\n";
		
		myScheduler.addTask("Dance", "Studio", "0900", "1000", "Recreation", "140314");
		myScheduler.addTask("Dances", "Studio", "1000", "1100", "Recreation", "140314");
		myScheduler.addTask("Danced", "Studio", "1100", "1200", "Recreation", "140314");
		bool smallUI = true;
		myScheduler.viewAll(smallUI);

		Assert::AreEqual(correctString, myScheduler.deleteTask("1"));
	}

	TEST_METHOD(ViewDateFunctionInvalidDateWithTooFewNumbersInserted) {
		TaskItScheduler myScheduler;
		bool dummy = true;
		string actual = "-";

		string correctString = INVALID_DATE + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		try {
			myScheduler.viewDate("14031", dummy);
		}
		catch (string error){
			Assert::AreEqual(correctString, error);
		}
	}
	
	TEST_METHOD(ViewDateFunctionInvalidDateWithWrongMonth) {
		TaskItScheduler myScheduler;
		bool dummy = true;
		string actual = "-";

		string correctString = INVALID_DATE + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		try {
			myScheduler.viewDate("141314", dummy);
		}
		catch (string error){
			Assert::AreEqual(correctString, error);
		}
	}

	TEST_METHOD(ViewDateFunctionInvalidDateWithWrongDay) {
		TaskItScheduler myScheduler;
		bool dummy = true;
		string actual = "-";

		string correctString = INVALID_DATE + NEW_LINE;
		myScheduler.addTask("Dances", "Studio", "0900", "1000", "Recreation", "140314");
		try {
			myScheduler.viewDate("320314", dummy);
		}
		catch (string error){
			Assert::AreEqual(correctString, error);
		}
	}

	};
}